<?php

namespace app\api\model\music;

use app\logic\model\music\MusicSelectedPackDetailLogicModel;

class MusicSelectedPackDetailApiModel extends MusicSelectedPackDetailLogicModel
{

    public static function getPackIdByMusicId(array $music_id_arr)
    {
        return array_unique(self::whereIn('music_id',$music_id_arr)->column('pack_id'));
    }


    public static function getDetailByPackId($pack_id,$field='id,music_id')
    {
        $details = self::where('pack_id',$pack_id)->field($field)->order('sort desc,id desc')->select()->toArray();
        $music_ids =array_column($details,'music_id');
        $musics = MusicApiModel::getInfosByIds($music_ids,'id,user_id,title,img');
        $musics = array_column($musics,null,'id');
        foreach ($details as &$val){
            $val['music'] = $musics[$val['music_id']]??[];
        }
        unset($val);
        return $details;
    }
}